<?
session_start();
if($_SESSION["logged"]){session_unset();session_destroy();}

include "sqlManager.php";

$sqlManager = new sqlManager();

if(isset($_POST[login])){
    if(empty($_POST[username])){
        $report['username'] = "Vyplnte username";
    }
    if(empty($_POST[password])){
        $report['passwordEmpty'] = "Vyplne heslo.";
    }
    if($sqlManager->login($_POST[username], $_POST[password]) && empty($report)){
        unset($report);
        session_start();
        $_SESSION['logged']=true;
        $_SESSION['name']=$sqlManager->getName($_POST[username]);
        $_SESSION['username']=$_POST[username];
        ?>
            <meta http-equiv="refresh" content="0;url=http://databaze.fbmi.cvut.cz/fialadom/BITWA/CV5/CV5_bmi_db_SQL.php">
        <?
    }else{
        $final = "Chyba prihlaseni.";
        $_SESSION['logged']=false;
    }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="zajimaveeeeeee" content="PhpStorm 7.0">
    <link rel="stylesheet" type="text/css" href="style.css">
    <title>BITWA - Fiala Dominik</title>

</head>
<body>
<div id="hlavicka">
    <h1 align="center">BITWA</h1><br>
</div>
<div id="menu">
    <? include "menu.php" ?>
</div>
<div id="obsah">
    <form method="POST" action="" >

        <label for="username"> Username </label>
        <input type="text" id="username" name="username" placeholder="username" value="<?php echo $_POST['username'];?>">
        <br/>
        <label for="password"> Heslo </label>
        <input type="password" id="password" name="password" ">

        <input type="submit" name="login" value="login">
    </form>
    <br><b>
        <?php
        foreach($report as $ch){
            echo "<b>".$ch."</b><br>";
        }
        unset($report);
        echo $final;
        ?>
    </b>
</div>
<div id="copyright">
    &copy fialadom
</div>
</body>
</html>